﻿CREATE PROCEDURE usix.s_AddressFix AS
DECLARE @SQL varchar(max)
SET @SQL = (
SELECT  dbo.sprint4('EXEC usix.s_Export_Short_AddOn %s,%s,%s%s',CF.UsixID,CF.CompanyID_Raw,CF.LoanID,CHAR(10))
FROM         t_Borrower INNER JOIN
                      t_Loan_Borrower ON t_Borrower.ID = t_Loan_Borrower.BorrowerID INNER JOIN
                      usix.t_CustomerFile_Export CF ON t_Loan_Borrower.LoanID = CF.LoanID INNER JOIN
                      t_Address ON t_Borrower.ID = t_Address.BorrowerID
WHERE     (t_Loan_Borrower.Pos = 0) AND (ISNULL(t_Address.Street, '') = '') AND (CF.Address > '') AND (t_Loan_Borrower.LoanID > 0) 
                      AND (t_Address.Pos = 0)
					FOR XML PATH('')
)
PRINT @SQL
EXEC (@SQL)
EXEC admin.s_Mail_System 'usix.s_AddressFix',@SQL,''
